package com.yayo.mangement.converter.db;

import com.yayo.mangement.converter.ColumnConverter;
import com.yayo.mangement.authentication.enums.PropertyTypeEnum;
import org.springframework.stereotype.Component;

@Component
public class MySqlColumnConverter implements ColumnConverter {

    @Override
    public PropertyTypeEnum processConverter(String columnType) {
        if(columnType != null)
            columnType = columnType.toUpperCase();
        if("TINYINT".equals(columnType) || "SMALLINT".equals(columnType) || "MEDIUMINT".equals(columnType) || "INT".equals(columnType)){
            return PropertyTypeEnum.INTEGER;
        } else if("BIGINT".equals(columnType)){
            return PropertyTypeEnum.LONG;
        } else if ("FLOAT".equals(columnType)){
            return PropertyTypeEnum.FLOAT;
        } else if("DOUBLE".equals(columnType) || "DECIMAL".equals(columnType)){
            return PropertyTypeEnum.DOUBLE;
        } else if("DATE".equals(columnType) || "DATETIME".equals(columnType)){
            return PropertyTypeEnum.DATE;
        } else if("TIME".equals(columnType)){
            return PropertyTypeEnum.TIME;
        } else if("TIMESTAMP".equals(columnType)){
            return PropertyTypeEnum.TIMESTAMP;
        } else{
            return PropertyTypeEnum.STRING;
        }
    }

}
